package com.icinfo.cloud.provider.punish.api.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.CertTypeEnum;
import com.icinfo.cloud.provider.common.enums.DocumentKindEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.ConvertUpMoneyUtil;
import com.icinfo.cloud.provider.punish.api.dto.*;
import com.icinfo.cloud.provider.punish.api.service.ICaseInfoShareService;
import com.icinfo.cloud.provider.punish.api.vo.*;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentRecordStatusEnum;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.model.SysDepartParam;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.config.service.ISysDepartParamService;
import com.icinfo.cloud.provider.punish.csource.manage.enums.CaseSourceEnum;
import com.icinfo.cloud.provider.punish.csource.manage.mapper.CaseSourceRegisterMainInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseHandlePersonRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICasePartiesRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CasePartiesRecordVo;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.mybatis.pagehelper.PageHelper;
import com.icinfo.framework.tools.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author shishengyao
 * @description
 * @date 2022/7/18
 */
@Service
public class CaseInfoShareServiceImpl implements ICaseInfoShareService {

    @Resource
    private CaseMainInfoMapper caseMainInfoMapper;
    @Resource
    private CasePartiesRecordMapper casePartiesRecordMapper;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;
    @Resource
    private ICaseHandlePersonRecordService caseHandlePersonRecordService;
    @Resource
    private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;
    @Resource
    private CaseReasonMainRecordMapper caseReasonMainRecordMapper;
    @Resource
    private CaseSourceRegisterMainInfoMapper caseSourceRegisterMainInfoMapper;
    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;
    @Resource
    private ISysDepartParamService sysDepartParamService;
    @Override
    public List<CaseInfoShareVo> getCaseInfoPageList(CaseInfoSharePageQueryDto pageQueryDto) {
        PageHelper.startPage(pageQueryDto.getPageNum(), pageQueryDto.getLength());
        List<CaseInfoShareVo> caseInfoShareVos = caseMainInfoMapper.selectCaseInfoByHandlePersonIdList(pageQueryDto);
        if (ObjectUtil.isNotEmpty(caseInfoShareVos) && caseInfoShareVos.size()>0){
            for (CaseInfoShareVo vo :caseInfoShareVos){
                if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(vo.getCasePartiesReasonType())){
                    List<CasePartiesRecordVo> partiesRecords = casePartiesRecordService.getCasePartiesInfo(vo.getCaseId());
                    String partyTitle = partiesRecords.get(0).getPartyName() + "等" + partiesRecords.size() + "个当事人";
                    vo.setPartyName(partyTitle);
                }
            }
        }
        return caseInfoShareVos;
    }

    @Override
    public List<CasePartyInfoShareVo> getCasePartyListByCaseId(String caseId) {
        List<CasePartyInfoShareVo> casePartyInfoShareVos = casePartiesRecordMapper.selectCasePartiesRecordByCaseId(caseId);
        if (ObjectUtil.isNotEmpty(casePartyInfoShareVos) && casePartyInfoShareVos.size()>0){
            for (CasePartyInfoShareVo partyInfoVo:casePartyInfoShareVos){
                partyInfoVo.setPartyIdentityTypeDesc(CertTypeEnum.getValueByCode(partyInfoVo.getPartyIdentityTypeCode()));
                if (PartyTypeEnum.LEGAL.getCode().equals(partyInfoVo.getPartyType())){
                    partyInfoVo.setPartyIdentityTypeDesc("统一社会信用代码");
                }
            }
        }
        return casePartyInfoShareVos;
    }

    /**
     * 描述： 根据承办人查询案件记录(分页)
     *
     * @author: zhengqiang
     * @date: 2022/9/7
     * @param: pageQueryDto
     * @return {@link List<  CaseInfoRecordVo >}
     **/
    //读库注解
    @DS("punishRead")
    @Override
    public List<CaseInfoRecordVo> getCaseInfoListByUser(CaseInfoRecordPageQueryDto pageQueryDto) {
        PageHelper.startPage(pageQueryDto.getPageNum(), pageQueryDto.getLength());
        List<CaseInfoRecordVo> caseInfoVos = caseMainInfoMapper.selectCaseInfoListByUser(pageQueryDto);
        if (!ObjectUtils.isEmpty(caseInfoVos)){
            for (CaseInfoRecordVo vo : caseInfoVos) {
                //当事人名称处理
                List<CasePartiesRecordVo> partiesRecords = casePartiesRecordService.getCasePartiesInfo(vo.getCaseId());
                if (!ObjectUtils.isEmpty(partiesRecords)) {
                    if (partiesRecords.size() > 1) {
                        String partyTitle = partiesRecords.get(0).getPartyName() + "等" + partiesRecords.size() + "个当事人";
                        vo.setPartyName(partyTitle);
                    } else {
                        vo.setPartyName(partiesRecords.get(0).getPartyName());
                    }
                }
                //案件类型处理
                vo.setCaseType(CaseTypeEnum.getValueByCode(vo.getCaseType()));
                //承办人名称处理
                List<CaseHandlePersonRecord> personList = caseHandlePersonRecordService.getCaseHandlePersonRecordList(vo.getCaseId());
                if (!ObjectUtils.isEmpty(personList)) {
                    String handlePersonName = personList.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining(","));
                    vo.setHandlePersonName(handlePersonName);
                }

                //分别处罚时,处罚种类处理
                if (HandleTypeEnum.PART_PUNISH.getCode().equals(vo.getHandleType())) {
                    Example auxiliaryExample=new Example(CaseMainDetailAuxiliaryInfo.class);
                    auxiliaryExample.createCriteria().andEqualTo("caseId", vo.getCaseId());
                    List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(auxiliaryExample);
                    if(!ObjectUtils.isEmpty(caseMainDetailAuxiliaryInfos)){
                        //处罚种类
                        Set<String> kindSet = new HashSet<>();
                        for (CaseMainDetailAuxiliaryInfo auxiliaryInfo : caseMainDetailAuxiliaryInfos) {
                            if (!ObjectUtils.isEmpty(auxiliaryInfo.getPunishKinds())) {
                                String[] split = auxiliaryInfo.getPunishKinds().split(",");
                                Collections.addAll(kindSet, split);
                            }
                        }
                        String punishKinds = kindSet.stream().collect(Collectors.joining(","));
                        vo.setPunishKinds(punishKinds);
                    }
                }

                //案由处理
                Example example = new Example(CaseReasonMainRecord.class);
                example.createCriteria().andEqualTo("caseId",vo.getCaseId()).andEqualTo("status","1");
                List<CaseReasonMainRecord> records = caseReasonMainRecordMapper.selectByExample(example);
                if (!ObjectUtils.isEmpty(records)) {
                    String reasonName = records.stream().map(reason -> reason.getCaseReasonName()).collect(Collectors.joining(","));
                    vo.setCaseReason(reasonName);
                }
            }
        }
        return caseInfoVos;
    }

    /**
     * 描述： 根据案件id获取分当事人案件详情 (事项抄告)
     *
     * @author: zhengqiang
     * @date: 2022/10/19
     * @param: caseId
     * @return {@link List<  PartiesCaseInfoOfExtVo >}
     **/
    @Override
    public List<PartiesCaseInfoOfExtVo> getPartiesCaseInfoByCaseIdOfExt(String caseId) {
        List<PartiesCaseInfoOfExtVo> caseInfoOfPartiesVos = caseMainInfoMapper.selectPartiesCaseInfoByCaseIdOfExt(caseId);
        if (!ObjectUtils.isEmpty(caseInfoOfPartiesVos)) {
            caseInfoOfPartiesVos.forEach(e -> {
                e.setCaseType(CaseTypeEnum.getValueByCode(e.getCaseType()));
                e.setCaseStatus(CaseStatusEnum.getValueByCode(e.getCaseStatus()));

                //分别处罚时: 处罚种类,处罚金额,处罚决定书号
                if (HandleTypeEnum.PART_PUNISH.getCode().equals(e.getHandleType())) {
                    Example auxiliaryExample = new Example(CaseMainDetailAuxiliaryInfo.class);
                    auxiliaryExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("partyId", e.getPartyId());
                    List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(auxiliaryExample);
                    if(!ObjectUtils.isEmpty(caseMainDetailAuxiliaryInfos)) {
                        CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryInfos.get(0);
                        e.setPunishKinds(caseMainDetailAuxiliaryInfo.getPunishKinds());
                        e.setDraftPunishMoney(caseMainDetailAuxiliaryInfo.getDraftPunishMoney());
                        e.setPunishDocumentNumber(caseMainDetailAuxiliaryInfo.getPunishDocumentNumber());
                    }
                }
            });
        }
        return caseInfoOfPartiesVos;
    }

    /**
     * 描述： 根据办案人员获取办案中的案件记录(分页) (联合会商、争议裁决调用)
     *
     * @author: zhengqiang
     * @date: 2022/10/19
     * @param: pageQueryDto
     * @return {@link List< CaseInfoRecordOfExtVo>}
     **/
    //读库注解
    @DS("punishRead")
    @Override
    public List<CaseInfoRecordOfExtVo> getCaseInfoPageRecordByUserOfExt(CaseInfoRecordPageQueryOfExtDto pageQueryDto) {
        PageHelper.startPage(pageQueryDto.getPageNum(), pageQueryDto.getLength());
        List<CaseInfoRecordOfExtVo> caseInfoVos = caseMainInfoMapper.selectCaseInfoRecordByUserOfExt(pageQueryDto);
        return caseInfoVos;
    }

    /**
     * 描述： 根据案件id获取案件记录 (联合会商、争议裁决调用)
     *
     * @author: zhengqiang
     * @date: 2022/10/19
     * @param: caseId
     * @return {@link CaseInfoRecordOfExtVo}
     **/
    @Override
    public CaseInfoRecordOfExtVo getCaseInfoRecordByCaseIdOfExt(String caseId) {
        CaseInfoRecordOfExtVo caseInfoRecordOfExtVo = caseMainInfoMapper.selectCaseInfoRecordByCaseIdOfExt(caseId);
        return caseInfoRecordOfExtVo;
    }

    /**
     * 描述： 根据主体身份证或代码社会信用代码查询处罚记录(分页) (信息协助)
     *
     * @author: zhengqiang
     * @date: 2022/10/19
     * @param: pageQueryDto
     * @return {@link List< PartiesPunishRecordOfExtVo>}
     **/
    //读库注解
    @DS("punishRead")
    @Override
    public List<PartiesPunishRecordOfExtVo> getPartiesPunishRecordByIdCodeOfExt(PartiesPunishRecordPageQueryOfExtDto pageQueryDto) {
        PageHelper.startPage(pageQueryDto.getPageNum(), pageQueryDto.getLength());
        List<PartiesPunishRecordOfExtVo> partiesPunishRecordOfExtVos = caseMainInfoMapper.selectPartiesPunishRecordByIdCodeOfExt(pageQueryDto);
        partiesPunishRecordOfExtVos.forEach(e -> {
            if (CaseTypeEnum.SIMPLE_PROCEDURE.getCode().equals(e.getCaseType())) {
                //简易处罚拼接处罚内容
                String punishContent = "人民币" + ConvertUpMoneyUtil.toChinese(e.getDraftPunishMoney()) + "整（¥" + e.getDraftPunishMoney() + "）的处罚";
                if (e.getPunishKinds().contains("警告") && e.getPunishKinds().contains("罚款")) {
                    punishContent = "警告及" + punishContent;
                } else if ("警告".equals(e.getPunishKinds())) {
                    punishContent = "警告";
                }
                e.setPunishContent(punishContent);
            }
        });
        return partiesPunishRecordOfExtVos;
    }

    /**
     * 描述： 根据办案人员获取办案中的案源记录(分页)
     *
     * @author: zhengqiang
     * @date: 2023/02/20
     * @param: pageQueryDto
     * @return {@link List< CaseSourceInfoRecordOfExtVo>}
     **/
    @Override
    public List<CaseSourceInfoRecordOfExtVo> getCaseSourceInfoPageRecordByUserOfExt(CaseSourceInfoRecordPageQueryOfExtDto pageQueryDto) {
        PageHelper.startPage(pageQueryDto.getPageNum(), pageQueryDto.getLength());
        List<CaseSourceInfoRecordOfExtVo> caseInfoVos = caseSourceRegisterMainInfoMapper.selectCaseSourceInfoRecordByUserOfExt(pageQueryDto);
        caseInfoVos.forEach(e -> {
            e.setCaseSource(CaseSourceEnum.getValueByCode(e.getCaseSource()));
        });
        return caseInfoVos;
    }

    /**
     * 描述： 根据案件id查询处罚决定信息
     *
     * @author: zhengqiang
     * @date: 2023/3/1
     * @param: caseId
     * @return {@link List< CasePunishDecisionInfoVo>}
     **/
    public List<CasePunishDecisionInfoVo> getCasePunishDecisionInfoByCaseId(String caseId) {
        List<CasePunishDecisionInfoVo> casePunishDecisionInfoVos = new ArrayList<>();
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
        if (ObjectUtil.isEmpty(caseMainInfo)) {
            return casePunishDecisionInfoVos;
        }
        String busiParamId = caseMainInfo.getBusiParamId();
        ConfigBusiParamDocumentInfo configBusiParamDocumentInfo =
                configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(busiParamId, DocumentKindEnum.DOC_KIND_CFJDS.getCode());
        if (ObjectUtil.isEmpty(configBusiParamDocumentInfo)) {
            return casePunishDecisionInfoVos;
        }
        Example exampleDocRed = new Example(CaseDocumentRecord.class);
        Example.Criteria criteria = exampleDocRed.createCriteria();
        criteria.andEqualTo("caseId", caseId).andEqualTo("documentCatalogCode", configBusiParamDocumentInfo.getDocumentCatalogCode())
                .andEqualTo("documentRecordStatus", DocumentRecordStatusEnum.NORMAL.getCode());
        List<CaseDocumentRecord> caseDocumentRecords = caseDocumentRecordMapper.selectByExample(exampleDocRed);
        if (ObjectUtil.isEmpty(caseDocumentRecords)) {
            return casePunishDecisionInfoVos;
        }
        caseDocumentRecords.forEach(e -> {
            CasePunishDecisionInfoVo casePunishDecisionInfoVo = new CasePunishDecisionInfoVo();
            casePunishDecisionInfoVo.setCaseId(caseId);
            casePunishDecisionInfoVo.setPunishDocumentUrl(ObjectUtil.isNotEmpty(e.getDocumentUrlAfterSeal()) ? e.getDocumentUrlAfterSeal() : e.getDocumentUrl());
            casePunishDecisionInfoVo.setPunishDocumentCreateTime(e.getDocumentCreateTime());
            casePunishDecisionInfoVo.setHandlePersonName(e.getCreateUserName());
            casePunishDecisionInfoVo.setHandleOrgName(caseMainInfo.getCaseOrgName() + "/" + caseMainInfo.getCaseDeptName());
            casePunishDecisionInfoVos.add(casePunishDecisionInfoVo);
        });
        return casePunishDecisionInfoVos;
    }

    /**
     * 根据caseId获取案件条线信息与案文书抬头
     * @author liyafeng
     * @date 2023/3/8
      * @param caseId
     * @return {@link CaseLineStandardNameInfoVo}
     */
    @Override
    public CaseLineStandardNameInfoVo getCaseLineStandardNameInfo(String caseId) {
        CaseLineStandardNameInfoVo vo=new CaseLineStandardNameInfoVo();
        if(StringUtils.isBlank(caseId)){
            throw new BusinessException("案件id不能为空");
        }
        CaseMainInfo caseMainInfo=caseMainInfoMapper.selectByPrimaryKey(caseId);
        if(!ObjectUtils.isEmpty(caseMainInfo)){
            vo.setLineCode(caseMainInfo.getLineCode());
            vo.setLineName(caseMainInfo.getLineName());
            SysDepartParam sysDepartParam=sysDepartParamService.getSysDepartParamByOrgCodeAndDeptCode(caseMainInfo.getCaseOrgCode(),caseMainInfo.getCaseDeptCode());
            if(!ObjectUtils.isEmpty(caseMainInfo)){
                vo.setOrgStandardName(sysDepartParam.getOrgStandardName());
            }
        }
        return vo;
    }

    /**
     * 描述： 根据检查id查询案件信息列表
     *
     * @author: zhengqiang
     * @date: 2023/3/7
     * @param: checkIds 多个id以逗号分隔
     * @return {@link List< CheckTransferCaseRecordVo>}
     **/
    public List<CheckTransferCaseRecordVo> getCheckTransferCaseListByCheckIds(String checkIds) {
        List<CheckTransferCaseRecordVo> caseRecordVos = new ArrayList<>();
        if (ObjectUtil.isEmpty(checkIds)) {
            return caseRecordVos;
        }
        String[] idArr = checkIds.split(",");
        for (String id : idArr) {
            CheckTransferCaseRecordVo caseRecordVo = new CheckTransferCaseRecordVo();
            Example example = new Example(CaseMainInfo.class);
            example.createCriteria().andEqualTo("dataSourceServiceId", id);
            List<CaseMainInfo> caseMainInfos = caseMainInfoMapper.selectByExample(example);
            if (ObjectUtil.isEmpty(caseMainInfos)) {
                continue;
            }
            CaseMainInfo caseMainInfo = caseMainInfos.get(0);
            BeanUtils.copyProperties(caseMainInfo, caseRecordVo);
            caseRecordVo.setCaseId(caseMainInfo.getId());
            caseRecordVo.setHandleOrgName(caseMainInfo.getCaseOrgName());
            caseRecordVo.setCaseStageName(caseMainInfo.getCaseCurrentStageName());
            caseRecordVo.setCaseTypeName(CaseTypeEnum.getValueByCode(caseMainInfo.getCaseType()));
            caseRecordVo.setCaseRegisterTime(caseMainInfo.getCaseRegistTime());

            //承办人名称处理
            List<CaseHandlePersonRecord> personList = caseHandlePersonRecordService.getCaseHandlePersonRecordList(caseMainInfo.getId());
            if (!ObjectUtils.isEmpty(personList)) {
                String handlePersonName = personList.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining("、"));
                caseRecordVo.setHandlePersonName(handlePersonName);
            }
            caseRecordVos.add(caseRecordVo);
        }
        return caseRecordVos;
    }
    /**
     * 案件信息查询(协同调用)
     * @param caseDto
     * @return
     */
    //读库注解
    @DS("punishRead")
    public List<AllCaseInfoOfExtVo> getAllCaseInfoListOfExt(AllCaseInfoQueryOfExtDto caseDto) {
        if (caseDto.getLength() > 1000) {
            throw new BusinessException("每页条数不能超过1000");
        }
        PageHelper.startPage(caseDto.getPageNum(), caseDto.getLength());
        List<AllCaseInfoOfExtVo> list = caseMainInfoMapper.selectAllCaseInfoListOfExt(caseDto);
        System.out.println(System.currentTimeMillis());
        list.forEach(e -> {
            //办案人员处理
            if (StringUtils.isNotBlank(e.getHandlePersonName())) {
                if (e.getHandlePersonName().indexOf(";") > 0) {
                    String[] handlePersonNameArray = e.getHandlePersonName().split(";");
                    Set<String> handlePersonNameSets = Arrays.stream(handlePersonNameArray).collect(Collectors.toSet());
                    String handlePersonName = handlePersonNameSets.stream().collect(Collectors.joining("、"));
                    e.setHandlePersonName(handlePersonName);
                }
            } else {
                e.setHandlePersonName("");
            }

            e.setCaseReason(convertParamQueryFinish(e.getCaseReason()));
            e.setIllegalLevel(convertParamQueryFinish(e.getIllegalLevel()));
            e.setCaseType(convertParamQueryFinish(e.getCaseType()));
            e.setCaseStatus(convertParamQueryFinish(e.getCaseStatus()));
            e.setCaseNumber(convertParamQueryFinish(e.getCaseNumber()));
            e.setCaseSource(convertParamQueryFinish(e.getCaseSource()));
            e.setCaseRegistTime(convertParamQueryFinish(e.getCaseRegistTime()));
            e.setCaseTimeLimit(convertParamQueryFinish(e.getCaseTimeLimit()));
            e.setCaseVerdictEndTime(convertParamQueryFinish(e.getCaseVerdictEndTime()));
            e.setDocumentNumber(convertParamQueryFinish(e.getDocumentNumber()));
            e.setCaseEndTime(convertParamQueryFinish(e.getCaseEndTime()));
            e.setPunishKinds(convertParamQueryFinish(e.getPunishKinds()));
            e.setExecuteWay(convertParamQueryFinish(e.getExecuteWay()));
            e.setHandleOrgName(convertParamQueryFinish(e.getHandleOrgName()));
            e.setHandleDeptName(convertParamQueryFinish(e.getHandleDeptName()));
            e.setCaseCreateTime(convertParamQueryFinish(e.getCaseCreateTime()));

            //TODO
            e.setConfiscateIllegalMoney(convertParamQueryFinish(e.getConfiscateIllegalMoney()));
            e.setDraftPunishMoney(convertParamQueryFinish(e.getDraftPunishMoney()));
            e.setCaseActsCode(convertParamQueryFinish(e.getCaseActsCode()));
            e.setCaseExternalActsCode(convertParamQueryFinish(e.getCaseExternalActsCode()));
            e.setCaseBarCodeUrl(convertParamQueryFinish(e.getCaseBarCodeUrl()));
            e.setCaseQrCodeUrl(convertParamQueryFinish(e.getCaseQrCodeUrl()));

            //3.caseType 翻译 案件类型:1简易程序  2一般程序  3快速办理
            e.setCaseType(CaseTypeEnum.getValueByCode(e.getCaseType()));
            if (Constant.STRING_3.equals(caseDto.getCaseType())) {
                e.setCaseType("涉刑移送");
            }
            //5. 0.待立案，1.立案审批 2.办案中.3.结案 5.中止 4.终止
            e.setCaseStatus(CaseStatusEnum.getValueByCode(e.getCaseStatus()));

            if (org.apache.commons.lang3.StringUtils.isNotBlank(e.getPartyName())) {
                if (e.getPartyName().indexOf(";") > 0) {
                    String[] partyNameArray = e.getPartyName().split(";");
                    Set<String> partySets = Arrays.stream(partyNameArray).collect(Collectors.toSet());
                    if (partySets.size() == 1) {
                        e.setPartyName(partySets.toArray()[0].toString());
                    } else {
                        e.setPartyName(partySets.toArray()[0].toString() + "等" + partySets.size() + "个");
                    }
                }
            } else {
                e.setPartyName("");
            }


            //计算罚款金额
            double draftPunishMoney, confiscateIllegalMoney;
            if (org.apache.commons.lang3.StringUtils.isNotBlank(e.getDraftPunishMoney())) {
                draftPunishMoney = Float.valueOf(e.getDraftPunishMoney());
            } else {
                draftPunishMoney = 0.00;
            }
            if (org.apache.commons.lang3.StringUtils.isNotBlank(e.getConfiscateIllegalMoney())) {
                confiscateIllegalMoney = Float.valueOf(e.getConfiscateIllegalMoney());
            } else {
                confiscateIllegalMoney = 0.00;
            }
            DecimalFormat dfmt = new DecimalFormat("##0.00");
            e.setPunishMoney(dfmt.format(draftPunishMoney + confiscateIllegalMoney));
        });
        return list;
    }
    private String convertParamQueryFinish(String param) {
        if (org.apache.commons.lang3.StringUtils.isNotBlank(param) && param.indexOf(";") >= 0) {
            if (";".equals(param)) {
                return "";
            } else {
                return param.substring(0, param.indexOf(";"));
            }
        } else {
            return param;
        }
    }
}
